<template>
  <article class="comment-components" ref="commentWrap">
  <cube-scroll v-if="isComment || typeof this.isComment === 'undefined'"
        ref="scroll"
        :options="options"
        @pulling-up="onPullingUp"
      >
    <div class="water-logo" v-if="list.length < 1">
      <img src="../../../static/images/dangjian/home/water-logo-comment.png" alt="">
    </div>
        <div class="block live-msg-wrap relative" v-for="(item,index) in list" :key="index">
          <div class="user-avatar">
            <div class="avatar">
              <!--<img src="../../../../static/images/slidepic.jpg" alt="">-->
              <img :src="tools.getAvatarUrl(item.commentUserId)" alt="">
            </div>
            <div class="head-my">
              <div class="info">
                <h1 class="">{{item.commentUser}} 说：</h1>
              </div>
              <div v-if="isMyComment(item.commentUserId) && allowDel" class="right" @click="deleteComment(item,index)">删除</div>
            </div>
          </div>
          <div class="live-msg">{{item.commentContent}}</div>
          <div class="card-foot">
            <p class="text">{{tools.getTimeNew(item.commentTime)}}</p>
            <div class="right">
              <div class="support"><ups :key="item.commentId" :contentId="contentId" :isUp="item.isUp" :shareType="shareType" :commentId="item.commentId" @updateUpsAdd="updateUpsAdd(item)" :upsCount="item.ups"></ups></div>
              <div class="support" @click.stop="onfocus(item,index)"><i v-if="allowComment"  class="icon-comment"></i>{{ item.commentTotal}}
              </div>
            </div>
            <input type="hidden" v-model="flag" />
          </div>
          <div v-if="item.child && item.child.length>0" class="split-my" @click="delChildComment(item,index)"><div class="split-inner"></div><div class="middle">收起</div><i class="icon-triangle-up"></i></div>
          <div v-else-if="item.commentTotal>0" class="split-my" @click="ChildComment(item,index)"><div class="split-inner"></div><div class="middle">展开{{ item.commentTotal }}条回复</div><i class="icon-triangle-down"></i></div>
          <!--            评论别人的心得的评论-->
          <div class="recomment-my-j" v-if="item.child" v-for="(child,indexChild) in item.child" :key="index+child.commentId">
            <input type="hidden" v-model="flag" />
            <div class="head-my title">
              <!--                <div>{{ child.createUserName }}{{ getMyself(child.createUser) }}<span-->
              <div>{{ child.userName }}<span
                class="arrow_left"></span>{{ child.replyToUser }}
              </div>
              <div v-if="isMyComment(child.userId)" @click.stop="del(child.commentId,indexChild,item)" class="right-one">删除
              </div>
            </div>
            <div class="span-my" v-html="tools.resumeEnter(child.content)">
            </div>
            <div class="text">
              <div>{{ tools.getTimeNew(child.commentTime) }}</div>
              <div class="right-my">
                <div @click.stop="upComment(child)" class="support" v-if="shareType === 7 || shareType === 5" >
                  <i class="icon-like" :class="{'icon-licked':child.isUp == true}"></i>
                  {{ child.ups || 0}}
<!--                  <i @click="upComment(child)" class="icon-like" :class="{'icon-licked':hashUp(child.commentId,child)}"></i>
                  {{ child.ups || 0}}{{child.isUp}}-->
<!--                  <ups :contentId="contentId" :isUp="child.isUp" :shareType="shareType" :commentId="child.commentId" :upsCount="child.ups"></ups>-->
                </div>
                <div class="support" v-else>
                  <upsTwo :commentId="child.commentId" :contentId="contentId" @updateUpsAdd="updateUpsAdd(child)" :upsCount="child.ups"></upsTwo>
                 </div>
                <div class="support" @click="onfocusOne(child,item.commentId,index)"><i class="icon-comment"></i></div>
              </div>
            </div>
          </div>
        </div>
        <div v-if="!hasMoreList()" class="no-message">已显示全部观点</div>
        <p class="pdv-10"></p>
        <p class="pdv-10"></p>
        <p class="pdv-5"></p>
      </cube-scroll>

    <!--留言寄语-->
    <!--<section class="foot-action">
      <div class="inner">
        <div class="full">
          &lt;!&ndash;<textarea :autoExpand="false" placeholder="说点什么" v-model="content"> </textarea>&ndash;&gt;
          <input placeholder="说点什么" type="text" v-model="content">
        </div>
        <div class="btn btn-small" @click="save()">
          <div class="default-block-btn">评论</div>
        </div>
      </div>
    </section>-->

    <liveMsgComponent ref="liveMsg" @newsSave="newsSave" @groupInfoSave="groupInfoSave" @spaceSave="spaceSave" @actionPush="actionPush" :isUp="isUp" :allowUp="allowUp" @message="onMessage" :isComment="isComment" v-if="preData.id" :shareType="shareType" :detail="preData" :commentList="true" @onComment="onComment" :contentId="preData.id" :comments="preData.comments" @onInputFocus="onInputFocus"></liveMsgComponent>

  </article>
</template>

<script>
  import { Textarea } from 'cube-ui'
  import ups from '@/components/common/upsComponent'
  import upsTwo from '@/components/common/upsTwoComponent'
  import liveMsgComponent from '@/components/common/liveMsgComponent'
  let myInfo = {}
  export default {
    name: 'commentListComponent',
    props: ['_contentId', 'shareType','isComment','allowUp','isUp'],
    components: {Textarea, ups, upsTwo, liveMsgComponent},
    data () {
      return {
        isShow: true,
        contentId: '',
        tabIndex: 0,
        pageIndex: 1,
        pageSize: 10,
        content: '',
        preData: {},
        options: {
          pullUpLoad: true,
          scrollbar: false
        },
        detail: {},
        list: [],
        flag:0,//用于刷新组件
        placeholder:'',
        replyToUser:'',//被回复人姓名
        replyToUserId:'',//被回复人id
        selectListIndex:0,//用于定位添加的列表索引
        onfocusStatus:0, //判断评论走谁的方法 0 默认 1 一级评论 2 二级评论
        isSubmiting:true,//防止重复提交 true 允许提交 false 不允许提交
        allowComment:true,//允许二级评论
        allowDel:true,//允许删除
      }
    },
    created () {
      console.log('this.isCommentthis.isComment===',this.isComment);
      if(typeof this.isComment === "undefined"){
      }
      this.adaptDetail()
      this.preData = this.$store.state.newsDetail
      console.log(this.preData)
      this.getList()
      myInfo = this.tools.getUserInfo()
    },
    watch: {
      _contentId (val, oldVal) {
        console.log('watch _contentId')
        this.preData = this.$store.state.newsDetail
        this.firstPage()
      }
    },
    methods: {
      onInputFocus(blo) {
        this.$emit('onInputFocus',blo);
      },
      updateUpsAdd(item){///用于给子组件增加点赞数
        item.ups++
        this.flag++
      },
      onfocus(item,index) { //一级评论的的回复
        console.log('onfocusNew',item);
        if(typeof item !== 'undefined'){
          this.placeholder = '回复'+item.commentUser+':'
          this.selectListIndex = index
          this.commentNewId = item.commentId
          this.replyToUser = item.commentUser
          this.replyToUserId = item.commentUserId
          this.onfocusStatus = 1
        }
        this.$refs.liveMsg.focusChild(this.placeholder);
        // this.textareaClass = 'on-focus'
      },
      onfocusOne(child,id,index){//二级评论
        console.log('onfocusOne',child);
        if(typeof child !== 'undefined'){
          this.placeholder = '回复'+child.userName+':'
          this.selectListIndex = index
          this.commentNewId = id
          this.replyToUser = child.userName
          this.replyToUserId = child.userId
          this.onfocusStatus = 2
        }
        this.$refs.liveMsg.focusChild(this.placeholder);
      },
      ChildComment(item, index) { //查询二级评论
        //组工信息的二级评论查看
        if(typeof this.shareType !='undefined' && this.shareType ===7){
          let dataNew = {
            contentId:this.contentId,
            pageNo: 1,
            pageSize: 1000,
            commentId: item.commentId,
          }
          this.fetchService.groupInfoCommentInfoPage(dataNew).then(res => {
            if (res.code !== 0) {
              return this.tools.tip(res.message)
            }
            this.list[index].child = this.getGroupInfoDateTwo(res.data)
            this.flag++
          })
          return
        }
        //支部空间二级评论查看
        if(this.$store.state.isSpace){
          let dataNew = {
            loginId: this.tools.getUserInfo().id,
            spaceId: this.contentId,
            pageNo: 1,
            pageSize: 1000,
            optLogId:item.commentId
          }
          this.fetchService.topic_commentListByLog(dataNew).then(res => {
            if (res.code !== 0) {
              return this.tools.tip(res.message)
            }
            console.log('res.datares.data=',res.data);
            res.data.forEach(item=>{
              item.isUp = item.selfSupport
              item.commentId = item.id
              item.ups = item.supportTotal || 0
              item.content = item.optContent || 0
              item.commentTime = item.createTime || ""
            })
            this.list[index].child = res.data
            console.log('this.list[index].child',this.list[index].child);
            this.flag++
          })
          return
        }
        let dataNew = {//新闻的二级评论
          contentId:this.contentId,
          pageNo: 1,
          pageSize: 1000,
          commentId: item.commentId,
        }
        this.fetchService.commentPage(dataNew).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message)
          }
          this.flag++
          this.getGroupInfoDateNews(index,res.data)
        })
      },
      delChildComment(item, index){ //清空二级评论
        this.flag--
        this.list[index].child = []
      },
      /*组工信息评论*/
      groupInfoSave (obj,callback) {
        let params = {
          content: obj.content,
          contentId: this.contentId,
          replyToUser: this.replyToUser,
          replyToUserId: this.replyToUserId,
          supCommentId: this.commentNewId
        }
        this.tools.showLoading()
        this.fetchService.groupInfoCommentInfo(params).then(res => {
          this.tools.hideLoading()
          callback(res.code);//把返回值传给子组件
          if (res.code === 0) {
            // let data = this.getGroupInfoDate(res.data)
            let data = res.data
            if(this.onfocusStatus === 0){ //判断评论走谁的方法 0 默认
              this.list.unshift(this.getGroupInfoDate(data))
              this.$refs.liveMsg.commentAdd()
            }else if(this.onfocusStatus === 1){//判断评论走谁的方法 1 一级评论
              this.list[this.selectListIndex].commentTotal++
              if(this.list[this.selectListIndex].child && this.list[this.selectListIndex].child.length>0){
                this.list[this.selectListIndex].child.push(this.getGroupInfoDateTwo(data))
              }
            }else if(this.onfocusStatus === 2){ //判断评论走谁的方法 2 二级评论
              this.list[this.selectListIndex].commentTotal++
              this.list[this.selectListIndex].child.push(data)
            }
            this.clearContent()
          }
          return this.tools.tip(res.message || '接口服务出错，请联系管理员', 2000)
        })
      },
      /*支部空间评论*/
      spaceSave (obj,callback) {
        let params = {
          optContent: obj.content,
          spaceId: this.contentId,
          replyToUser: this.replyToUser,
          replyToUserId: this.replyToUserId,
          optLogId: this.commentNewId
        }
        this.tools.showLoading()
        if (this.onfocusStatus === 0) { //判断评论走谁的方法 0 默认
          this.fetchService.topic_saveComment(params).then(res => {//一级评论
            this.tools.hideLoading()
            callback(res.code);//把返回值传给子组件
            if (res.code === 0) {
              // let data = this.getGroupInfoDate(res.data)
              let data = res.data
                this.list.unshift(this.getAdaptComentNew(data))
                this.$refs.liveMsg.commentAdd()
            }
          })
          this.clearContent()
          return this.tools.tip(res.message || '接口服务出错，请联系管理员', 2000)
        }
        this.fetchService.topic_saveCommentByLog(params).then(res => {//二级评论
          this.tools.hideLoading()
          callback(res.code);//把返回值传给子组件
          if (res.code === 0) {
            // let data = this.getGroupInfoDate(res.data)
            let data = res.data
            if(this.onfocusStatus === 1){//判断评论走谁的方法 1 一级评论
              this.list[this.selectListIndex].commentTotal++
              if(this.list[this.selectListIndex].child && this.list[this.selectListIndex].child.length>0){
                this.list[this.selectListIndex].child.push(this.getAdaptComentTwo(data))
              }
            }else if(this.onfocusStatus === 2){ //判断评论走谁的方法 2 二级评论
              this.list[this.selectListIndex].commentTotal++
              this.list[this.selectListIndex].child.push(this.getAdaptComentTwo(data))
            }
            this.clearContent()
          }
          return this.tools.tip(res.message || '接口服务出错，请联系管理员', 2000)
        })
      },
      /*新闻评论*/
      newsSave(obj,callback){
        /*let params = {
          "content": this.content,
          "contentId": this.contentId
        }*/
        let params = {
          content: obj.content,
          contentId: this.contentId,
          replyToUser: this.replyToUser,
          replyToUserId: this.replyToUserId,
          supCommentId: this.commentNewId
        }
        this.tools.showLoading()
        this.fetchService.commentAdd(params).then(res => {
          this.tools.hideLoading()
          callback(res.code);//把返回值传给子组件
          if (res.code === 0) {
            // let data = this.getGroupInfoDate(res.data)
            let data = res.data
            data.commentUserId = data.userId
            if(this.onfocusStatus === 0){ //判断评论走谁的方法 0 默认
              data.commentContent = data.content
              this.list.unshift(data)
              this.$refs.liveMsg.commentAdd()
              this.flag ++
            }else if(this.onfocusStatus === 1){//判断评论走谁的方法 1 一级评论
              this.list[this.selectListIndex].commentTotal++
              if(this.list[this.selectListIndex].child && this.list[this.selectListIndex].child.length>0){
                this.list[this.selectListIndex].child.push(this.getNewsInfoDate(data))
              }
              this.flag ++
            }else if(this.onfocusStatus === 2){ //判断评论走谁的方法 2 二级评论
              this.list[this.selectListIndex].commentTotal++
              this.list[this.selectListIndex].child.push(this.getNewsInfoDate(data))
              this.flag ++
            }
            this.clearContent()
          }
          return this.tools.tip(res.message || '接口服务出错，请联系管理员', 2000)
        })
      },
      clearContent(){//清空数据
        this.content = ''
        this.isSubmiting = true
        this.commentNewId = '' //清空commentNewId 防止前一个数据带过来
        this.replyToUser = '' //清空replyToUser
        this.replyToUserId = '' //清空replyToUserId
        this.onfocusStatus = 0
        // this.$refs.liveMsg.blur();//提交完成以后失去焦点
        return this.tools.tip('评论成功', 2000)
      },
      getGroupInfoDate(v){ // 组工信息处理数据
        let data = {
          commentContent: v.content || "",
          commentId: v.commentId || "",
          commentTime: v.commentTime || "",
          commentUser: v.userName || "",//评论人姓名
          commentUserId: v.userId || "", //评论人id
          downs: 0,
          photoId: v.userPhoto || "", // 评论人的头像id
          // ups: v.isUp === '1'
          ups: v.ups,
          isUp:v.isUp ==='1'? true : false,
          commentTotal: v.commentTotal, //评论条数
          contentId:v.contentId, //新闻id
          replyToUser:v.replyToUser,//被评论人id
          replyToUserId:v.replyToUserId,//被评论人姓名
          supCommentId:v.supCommentId, //次级评论id
        }
        return data
      },
      getGroupInfoDateTwo(data){ // 组工信息二级数据的处理
        data.isUp = data.isUp === '1' ? true : false
        data.ups = data.ups || 0
        data.commentTime = data.commentTime || ""
        return data
      },
      getAdaptComentNew(v){ // 支部空间处理数据
        let data = {
          commentContent: v.optContent || "",
          commentId: v.optLogId || "",
          commentTime: v.createTime || "",
          commentUser: v.userName || "",//评论人姓名
          commentUserId: v.userId || "", //评论人id
          downs: 0,
          photoId: v.userId || "", // 评论人的头像id
          // ups: v.isUp === '1'
          ups: v.supportTotal || 0,
          isUp:v.selfSupport ==='1'? true : false,
          commentTotal: v.commentTotal, //评论条数
          contentId:v.spaceId, //新闻id
          replyToUser:v.replyToUser,//被评论人姓名
          replyToUserId:v.replyToUserId,//被评论人id
          supCommentId:v.id, //次级评论id
        }
        return data
      },
      getAdaptComentTwo(data){ // 支部空间二级数据的处理
        data.isUp = data.selfSupport
        data.commentId = data.id
        data.ups = data.supportTotal || 0
        data.content = data.optContent || 0
        data.commentTime = data.createTime || ""
        return data
      },
      getGroupInfoDateNews(index,data){ // 新闻评论二级数据的处理 - 列表
        data.forEach( (item,index)=>{
          data[index].content = item.commentContent
          data[index].userName = item.commentUser
          data[index].userId = item.commentUserId
          data[index].isUp = false
           /*this.hashUp(item.commentId).then(res=>{
             console.log('resss===',res);
             data[index].isUp = res
          })*/
        })
        this.list[index].child = data
      },
      getNewsInfoDate(data){ // 新闻评论二级数据的处理
        data.userName = data.commentUser
        data.userId = data.commentUserId
        data.isUp = false
        return data
      },
      async hashUp(commentId,child) {//新闻单独请求点赞
        await this.fetchService.commentGetSfdz(commentId).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          child.isUp = res.data
        })
      },
      /*二级评论点赞*/
      upComment(item) {
        if (item.isUp == true) {
            return false
          }
          let params = {
            commentId: item.commentId,
            type: 1,
            contentId: this.contentId,
          }
          if(typeof this.shareType !='undefined' && this.shareType ===7){ //组工信息的评论点赞
            this.fetchService.groupInfoCommentInfoUps(params).then(res => {
              if (res.code !== 0) {
                return this.tools.tip(res.message || '接口服务出错，请联系管理员')
              }
              this.flag --
              item.isUp = true
              item.ups ++
              return res
            })
            return
          }
          if(this.$store.state.isSpace){ //支部空间的评论点赞
            let data = {
              id: item.id,
            }
            this.fetchService.topic_opt_subSupport(data).then(res => {
              if (res.code !== 0) {
                return this.tools.tip(res.message || '接口服务出错，请联系管理员')
              }
              this.flag --
              item.isUp = true
              item.ups ++
              return res
            })
            return
          }
          return this.fetchService.upsAndDowns(params).then(res => {//新闻适配点赞
            if (res.code !== 0) {
              return this.tools.tip(res.message || '接口服务出错，请联系管理员')
            }
            this.flag --
            item.isUp = true
            item.ups ++
            return res
          })
      },
      isMyComment(userId) {
        return userId === myInfo.id
      },
      //删除二级评论
      del(id, index,list) {
        let _this = this
        this.$createDialog({
          type: 'confirm',
          title: "温馨提示",
          content: '确认删除？',
          confirmBtn: {
            text: '确定',
            active: true,
            disabled: false,
            href: 'javascript:;'
          },
          cancelBtn: {
            text: '取消',
            active: false,
            disabled: false,
            href: 'javascript:;'
          },
          onConfirm: () => {
            if (_this.shareType === 7) {  //类型为组工信息
              return _this.deleteMaterial(id, index,list);
            }
            if (this.$store.state.isSpace) {
              return _this.deleteSpaceMaterial(id, index,list)
            }
            _this.fetchService.commentDeleteCommentByNews(id,this._contentId).then(res => {
              if (res.code === 0) {
                this.tools.tip("删除成功")
                list.child.splice(index, 1)
                list.commentTotal--
              }
            })
          },
          onCancel: () => {
          }
        }).show()
      },
      deleteMaterial(id, index,list) {
        this.fetchService.groupInfoCommentInfoDelete(id).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message)
          }
          this.tools.tip("删除成功")
          list.child.splice(index, 1)
          list.commentTotal--
        })
      },
      /*删除支部空间二级评论*/
      deleteSpaceMaterial(id, index,list) {
        let data={
          id:id
        }
        this.fetchService.topic_commentDelete(data).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message)
          }
          this.tools.tip("删除成功")
          list.child.splice(index, 1)
          list.commentTotal--
        })
      },
      /*删除评论*/
      deleteComment (item, index) {
        let me = this
        this.$createDialog({
          type: 'confirm',
          icon: '',
          title: '温馨提示',
          content: '确定删除？',
          confirmBtn: {
            text: '确定',
            active: true,
            disabled: false,
            href: 'javascript:;'
          },
          cancelBtn: {
            text: '取消',
            active: false,
            disabled: false,
            href: 'javascript:;'
          },
          onConfirm: () => {
            if (me.shareType === 7) {
              return me.groupInfoCommentInfoDelete(item.commentId, index)
            }
            if (this.$store.state.isSpace) {
              return me.spaceDelete(item.commentId, index)
            }
            me.fetchService.commentDeleteCommentByNews(item.commentId,this._contentId).then(res => {
              if (res.code === 0) {
                this.tools.tip('删除成功')
                me.list.splice(index, 1)
                this.$refs.liveMsg.commentDeduce()
              }
            })
          }
        }).show()
      },
      /*组工评论删除*/
      groupInfoCommentInfoDelete (id, index) {
        let me = this
        this.fetchService.groupInfoCommentInfoDelete(id).then(res => {
          if (res.code === 0) {
            this.tools.tip('删除成功')
            me.list.splice(index, 1)
            this.$refs.liveMsg.commentDeduce()
          }
        })
      },
      /*支部空间删除*/
      spaceDelete (id, index) {
        let me = this
        let data={
          id:id
        }
        this.fetchService.topic_commentDelete(data).then(res => {
          if (res.code === 0) {
            this.tools.tip('删除成功')
            me.list.splice(index, 1)
            this.$refs.liveMsg.commentDeduce()
          }
        })
      },
      /*保存评论之后*/
      onMessage () {
        this.firstPage()
        this.onComment()
      },
      /*点击消息按钮*/
      onComment () {
        this.$refs.commentWrap.scrollIntoView()
      },
      hasMoreList () {
        return !(this.list.length > 0 && this.noMore)
      },
      /*适配内容*/
      adaptDetail () {
        let data = this.$store.state.newsDetail
        this.$store.state.newsDetail.comments = data.countComment
      },
      /*适配组工信息留言*/
      getAdaptComent (data) {
        let ret = []
        data.forEach(v => {
          let item = {
            commentContent: v.optContent || "",
            commentId: v.id || "",
            commentTime: v.createTime || "",
            commentUser: v.userName || "",
            downs: 0,
            photoId: v.imageUrl || "",
            // ups: false,
            ups: v.supportTotal,
            isUp:v.selfSupport,
            commentUserId:v.userId,
            commentTotal:v.commentTotal
          }
          ret.push(item)
        })
        return ret
      },
      /*适配组工信息留言*/
      getAdaptComentGroupInfo (data) {
        let ret = []
        data.forEach(v => {
          let item = {
            commentContent: v.content || "",
            commentId: v.commentId || "",
            commentTime: v.commentTime || "",
            commentUser: v.userName || "",//评论人姓名
            commentUserId: v.userId || "", //评论人id
            downs: 0,
            photoId: v.userPhoto || "", // 评论人的头像id
            // ups: v.isUp === '1'
            ups: v.ups,
            isUp:v.isUp ==='1'? true : false,
            commentTotal: v.commentTotal, //评论条数
            contentId:v.contentId, //新闻id
            replyToUser:v.replyToUser,//被评论人id
            replyToUserId:v.replyToUserId,//被评论人姓名
            supCommentId:v.supCommentId, //次级评论id
          }
          ret.push(item)
        })
        return ret
      },
      /*支部空间*/
      getListSpace () {
        this.tabIndex = 0
        let id = this._contentId
        this.contentId = id
        let params = {
          loginId: this.tools.getUserInfo().id,
          spaceId: id,
          pageNo: this.pageIndex,
          pageSize: this.pageSize
        }
        // return this.fetchService.spaceInfoCommentList(params).then(res => {
        return this.fetchService.topic_commentList(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          if (res.data.length === 0 && this.pageIndex !== 1) {
//            this.tools.tip('已无更多数据')
            this.options.pullUpLoad = false
            this.noMore = true
          }
          this.pageIndex++
          this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate()
          let data = this.getAdaptComent(res.data)
          this.list = this.list.concat(data)
          console.log('this.listthis.list',this.list);
          return res
        })
      },
      /*组工信息*/
      loadDataGroupInfo () {
        this.tabIndex = 0
        let id = this._contentId
        this.contentId = id
        let params = {
          // userId: this.tools.getUserInfo().id,//2021年1月4日 14:45:26 修复组工信息只能看到自己的评论
          contentId: id,
          pageNo: this.pageIndex,
          pageSize: this.pageSize
        }
        return this.fetchService.groupInfoCommentInfoPage(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          if (res.data.length === 0 && this.pageIndex !== 1) {
//            this.tools.tip('已无更多数据')
            this.options.pullUpLoad = false
            this.noMore = true
          }
          this.pageIndex++
          this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate()
          let data = this.getAdaptComentGroupInfo(res.data)
          this.list = this.list.concat(data)
          console.log('this.listthis.list',this.list);
          // debugger
          return res
        })
      },
      /*新闻类*/
      getList () {
        if (this.$store.state.isSpace) {
          // this.allowComment= false
          // this.allowDel= false
          return this.getListSpace()
        }
        if (this.shareType === 7) {
          return this.loadDataGroupInfo()
        }
        this.tabIndex = 0
        let id = this._contentId
        this.contentId = id
        let params = {
          contentId: id,
          pageNo: this.pageIndex,
          pageSize: this.pageSize
        }
        return this.fetchService.commentPage(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          if (res.data.length === 0 && this.pageIndex !== 1) {
            this.options.pullUpLoad = false
//            this.tools.tip('已无更多数据')
            this.noMore = true
          }
          this.pageIndex++
          this.list = this.list.concat(res.data)
          this.$nextTick(() => {
            this.$refs.scroll && this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate()
          })
          return res
        })
      },
      liveMessage () {
        this.tabIndex = 1
      },
      save () {
        if (this.content.length == 0 || this.content.trim().length == 0) {
          return this.tools.alert('请填写留言')
        }
        let params = {
          "content": this.content,
          "contentId": this.preData.id
        }
        this.tools.showLoading()
        this.fetchService.commentAdd(params).then(res => {
          this.tools.hideLoading()
          if (res.code === 0) {
            this.content = ''
            this.firstPage()
            this.$store.state.newsDetail.comments++
            return this.tools.alert('评论成功')
          }
        })
      },
      firstPage () {
        this.list = []
        this.pageIndex = 1
        this.getList()
      },
      onPullingUp () {
        this.$refs.commentWrap.scrollIntoView()
        this.getList().then(res => {
          setTimeout(() => {
            this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
            // this.options.pullUpLoad = false
          }, 100)
        })
      },
      show () {
        this.isShow = true
      },
      back () {
        this.isShow = false
      },
      //行为记录
      actionPush(actionType){
        this.$emit('log',actionType)
      }
    }
  }
</script>

<style scoped lang="scss">
  @import "@/common/stylus/moon.scss";
  .comment-components {
    height:100%;
  }
</style>
